<?php
// +----------------------------------------------------------------------
//            -------------------------
//           /   / ----------------\  \
//          /   /             \  \
//         /   /              /  /
//        /   /    /-------------- /  /
//       /   /    /-------------------\  \
//      /   /                   \  \
//     /   /                     \  \
//    /   /                      /  /
//   /   /      /----------------------- /  /
//  /-----/      /---------------------------/
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://baimifan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: Sage 2016/4/22  9:27
// +----------------------------------------------------------------------
namespace Admin\Controller;
use Common\Model\BookModel;
use Admin\Common\Page;
use Think\Model;

Class SearchStockController extends CashierBaseController{

    function index(){
        $map['is_del'] = 0;
        $keywords = I('get.keywords');
        if (!empty($keywords)) {
            $map_or['book_id'] = $keywords;
            $map_or['tm'] = $keywords;
            $map_or['spbs'] = $keywords;
            $map_or['sm'] = ['like' , "%{$keywords}%"];
            $map_or['_logic'] = 'OR';
            $map['_complex'] = $map_or;
        }
        $m = D('Book');
        $count = $m->where($map)->count();// 查询满足要求的总记录数
        $Page = new  Page($count , C('page.size'));// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $where['keywords'] = $keywords;
        foreach ($where as $key => $val) {
            $Page->parameter[ $key ] = urlencode($val);
        }
        $show = $Page->show();// 分页显示输出
        $this->assign('page' , $show);// 赋值分页输出
        $data = $m->where($map)->relation(TRUE)->order('book_id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
        $this->data = $data;
        $this->display();
    }
}